from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-21 14:03:33.564598
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 21, Jan, 2022
Time: 14:03:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.7846
Nobs: 543.000 HQIC: -48.2183
Log likelihood: 6322.53 FPE: 8.67217e-22
AIC: -48.4968 Det(Omega_mle): 7.35868e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.362721 0.070396 5.153 0.000
L1.Burgenland 0.103214 0.042674 2.419 0.016
L1.Kärnten -0.113272 0.022099 -5.126 0.000
L1.Niederösterreich 0.190170 0.088936 2.138 0.032
L1.Oberösterreich 0.127729 0.087962 1.452 0.146
L1.Salzburg 0.260778 0.045041 5.790 0.000
L1.Steiermark 0.025956 0.059495 0.436 0.663
L1.Tirol 0.105071 0.047932 2.192 0.028
L1.Vorarlberg -0.073861 0.042340 -1.744 0.081
L1.Wien 0.018282 0.078152 0.234 0.815
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064237 0.153268 0.419 0.675
L1.Burgenland -0.043652 0.092910 -0.470 0.638
L1.Kärnten 0.040431 0.048114 0.840 0.401
L1.Niederösterreich -0.205451 0.193634 -1.061 0.289
L1.Oberösterreich 0.452421 0.191512 2.362 0.018
L1.Salzburg 0.285471 0.098063 2.911 0.004
L1.Steiermark 0.111575 0.129533 0.861 0.389
L1.Tirol 0.307363 0.104358 2.945 0.003
L1.Vorarlberg 0.021708 0.092183 0.235 0.814
L1.Wien -0.024865 0.170153 -0.146 0.884
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196792 0.035909 5.480 0.000
L1.Burgenland 0.090475 0.021768 4.156 0.000
L1.Kärnten -0.007352 0.011273 -0.652 0.514
L1.Niederösterreich 0.235731 0.045366 5.196 0.000
L1.Oberösterreich 0.168777 0.044869 3.762 0.000
L1.Salzburg 0.038989 0.022975 1.697 0.090
L1.Steiermark 0.024799 0.030348 0.817 0.414
L1.Tirol 0.081027 0.024450 3.314 0.001
L1.Vorarlberg 0.054534 0.021597 2.525 0.012
L1.Wien 0.117881 0.039865 2.957 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.116582 0.036066 3.232 0.001
L1.Burgenland 0.043664 0.021863 1.997 0.046
L1.Kärnten -0.013887 0.011322 -1.227 0.220
L1.Niederösterreich 0.172068 0.045565 3.776 0.000
L1.Oberösterreich 0.338574 0.045066 7.513 0.000
L1.Salzburg 0.099579 0.023076 4.315 0.000
L1.Steiermark 0.109589 0.030481 3.595 0.000
L1.Tirol 0.090028 0.024557 3.666 0.000
L1.Vorarlberg 0.059226 0.021692 2.730 0.006
L1.Wien -0.015680 0.040040 -0.392 0.695
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.117806 0.068107 1.730 0.084
L1.Burgenland -0.044636 0.041286 -1.081 0.280
L1.Kärnten -0.045108 0.021380 -2.110 0.035
L1.Niederösterreich 0.141249 0.086044 1.642 0.101
L1.Oberösterreich 0.169967 0.085101 1.997 0.046
L1.Salzburg 0.281101 0.043576 6.451 0.000
L1.Steiermark 0.063153 0.057560 1.097 0.273
L1.Tirol 0.153161 0.046373 3.303 0.001
L1.Vorarlberg 0.094428 0.040963 2.305 0.021
L1.Wien 0.072675 0.075610 0.961 0.336
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.090516 0.052971 1.709 0.087
L1.Burgenland 0.019496 0.032111 0.607 0.544
L1.Kärnten 0.052660 0.016629 3.167 0.002
L1.Niederösterreich 0.190534 0.066922 2.847 0.004
L1.Oberösterreich 0.327590 0.066188 4.949 0.000
L1.Salzburg 0.037343 0.033892 1.102 0.271
L1.Steiermark -0.002454 0.044768 -0.055 0.956
L1.Tirol 0.122921 0.036067 3.408 0.001
L1.Vorarlberg 0.065008 0.031859 2.040 0.041
L1.Wien 0.097742 0.058807 1.662 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.168036 0.064153 2.619 0.009
L1.Burgenland 0.007033 0.038889 0.181 0.856
L1.Kärnten -0.065037 0.020139 -3.229 0.001
L1.Niederösterreich -0.108823 0.081049 -1.343 0.179
L1.Oberösterreich 0.217784 0.080160 2.717 0.007
L1.Salzburg 0.050504 0.041046 1.230 0.219
L1.Steiermark 0.253907 0.054218 4.683 0.000
L1.Tirol 0.496357 0.043681 11.363 0.000
L1.Vorarlberg 0.065333 0.038585 1.693 0.090
L1.Wien -0.081111 0.071220 -1.139 0.255
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159561 0.070997 2.247 0.025
L1.Burgenland -0.006795 0.043038 -0.158 0.875
L1.Kärnten 0.062453 0.022287 2.802 0.005
L1.Niederösterreich 0.178654 0.089695 1.992 0.046
L1.Oberösterreich -0.065907 0.088712 -0.743 0.458
L1.Salzburg 0.205500 0.045425 4.524 0.000
L1.Steiermark 0.137091 0.060002 2.285 0.022
L1.Tirol 0.056412 0.048341 1.167 0.243
L1.Vorarlberg 0.144405 0.042701 3.382 0.001
L1.Wien 0.131826 0.078819 1.673 0.094
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394110 0.041460 9.506 0.000
L1.Burgenland -0.003355 0.025133 -0.133 0.894
L1.Kärnten -0.020568 0.013015 -1.580 0.114
L1.Niederösterreich 0.203179 0.052379 3.879 0.000
L1.Oberösterreich 0.243197 0.051805 4.694 0.000
L1.Salzburg 0.033305 0.026527 1.256 0.209
L1.Steiermark -0.017233 0.035039 -0.492 0.623
L1.Tirol 0.086474 0.028229 3.063 0.002
L1.Vorarlberg 0.050917 0.024936 2.042 0.041
L1.Wien 0.033712 0.046028 0.732 0.464
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.034307 0.101902 0.167953 0.136676 0.089084 0.083525 0.030899 0.213168
Kärnten 0.034307 1.000000 -0.026518 0.133854 0.048025 0.084219 0.446643 -0.069416 0.093769
Niederösterreich 0.101902 -0.026518 1.000000 0.308354 0.126143 0.266573 0.068012 0.156950 0.281437
Oberösterreich 0.167953 0.133854 0.308354 1.000000 0.215239 0.294135 0.170195 0.136001 0.234440
Salzburg 0.136676 0.048025 0.126143 0.215239 1.000000 0.128966 0.087267 0.105388 0.127241
Steiermark 0.089084 0.084219 0.266573 0.294135 0.128966 1.000000 0.138879 0.104346 0.030089
Tirol 0.083525 0.446643 0.068012 0.170195 0.087267 0.138879 1.000000 0.064305 0.150507
Vorarlberg 0.030899 -0.069416 0.156950 0.136001 0.105388 0.104346 0.064305 1.000000 -0.004572
Wien 0.213168 0.093769 0.281437 0.234440 0.127241 0.030089 0.150507 -0.004572 1.000000